# Spatial merge (point-to-polygon) for IHP
# To run this program, change the working directory as appropriate.

setwd("~/Dropbox (MIT)/Research/NYC421a")

### Install packages

install.packages("sf")

### Load packages

library(sf)
library(foreign)

### Load data

df <- read.csv("data/raw/coordinates/coords_spc.csv")
attach(df)
points <- df[,2:3]

ihp <- st_read("data/GIS_boundaries/ihp/nycidha.shp")

points_sf <- st_as_sf(points, coords = c("longitude","latitude"),crs = st_crs(ihp))

### Assign IHP status

res <- as.data.frame(st_join(points_sf, ihp, join = st_within))
attach(res)

newdata <- cbind(df$bbl, res$DateAdopte)
colnames(newdata) <- c("bbl","date_ihp")

write.csv(newdata,file="data/raw/special_areas/ihp_status.csv",row.names=FALSE)


